/*
 ***************************************************************************
 * MediaTeK Inc.
 * 4F, No. 2 Technology	5th	Rd.
 * Science-based Industrial	Park
 * Hsin-chu, Taiwan, R.O.C.
 *
 * (c) Copyright 2002-2012, MTK.
 *
 * All rights reserved.	MediaTeK's source	code is	an unpublished work	and	the
 * use of a	copyright notice does not imply	otherwise. This	source code
 * contains	confidential trade secret material of MediaTeK Tech. Any attemp
 * or participation	in deciphering,	decoding, reverse engineering or in	any
 * way altering	the	source code	is stricitly prohibited, unless	the	prior
 * written consent of MediaTeK, Inc. is obtained.
 ***************************************************************************

	Module Name:
	omci_me_traffic_management_func.c

	Abstract:

	Revision History:
	Who			When			What
	--------	----------		----------------------------------------------
	Name		Date			Modification logs
	lisa.xue	2012/7/28	Create
*/

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>

#include "omci_adpt_general.h"

/*******************************************************************************************************************************
9.2.4: GEM interworking termination point

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_gem_interwork_tp_op[]={
	{0, "meId",                             2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "gem port network ctp conn ptr",    2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "iw option",                        1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_ENUM,         ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "service profile ptr",              2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{4, "iw termination point ptr",         2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{5, "pptp counter",                     1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{6, "operational state",                1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{7, "gal profile ptr",                  2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{8, "gal loopback cfg",                 1,  ATTR_ACCESS_R_W,                ATTR_FORMAT_ENUM,         ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{255, "",                               0,  0,                              0,                          0,                      NULL}
};

int omci_me_gem_iwtp_create_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	int ret=0;
	
	if(me_info==NULL || me_info->attributes == NULL)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] input paramter pointer is NULL\n",__FUNCTION__,__LINE__);
		return -1;
	}	
		
	ret = omci_me_general_set_op(me_entry,me_info);
	if(ret == OMCI_PARAM_ERROR)
	{	
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] return ret=%d\n",__FUNCTION__,__LINE__,ret);
		return ret;
	}
#ifdef TCSUPPORT_OMCI_ALCATEL
    omci_gem_interwork_tp_ptr gem_iwtp_ptr=NULL;
    gem_iwtp_ptr = (omci_gem_interwork_tp_ptr) me_info->attributes;
	ret = updateGemPortInfoToRomfile(gem_iwtp_ptr);
#endif	
	return ret;
}

int omci_me_gem_iwtp_delete_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
	int ret=0;
	
	if(me_info==NULL )
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d] input paramter pointer is NULL\n",__FUNCTION__,__LINE__);
		return -1;
	}
	
#ifdef TCSUPPORT_OMCI_ALCATEL	
    omci_gem_interwork_tp_ptr gem_iwtp_ptr=NULL;
	omci_me_info_t me_info_buf={0};

	me_info_buf.class_id = OMCI_CLASS_ID_GEM_INTERWORK_TP;
	me_info_buf.inst_id = me_info->inst_id; 	
	if(omci_attr_get_all_data_except_table_attr(&me_info_buf) != 0){
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]get data failed.\n",__FUNCTION__,__LINE__);
       	return -1;		
	}

    gem_iwtp_ptr = (omci_gem_interwork_tp_ptr) me_info_buf.attributes;
	ret = updateGemPortInfoToRomfile(gem_iwtp_ptr);
#endif	
	return ret;
}


omci_me_func_t omci_me_gem_interwork_tp_op ={
	omci_me_gem_iwtp_create_op, 
	omci_me_gem_iwtp_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_gem_interwork_tp_t omci_gem_interwork_tp_attr_data = {0};

omci_attr_t omci_gem_interwork_tp_attr ={
	(uint8_t *)&omci_gem_interwork_tp_attr_data,
	sizeof(omci_gem_interwork_tp_attr_data)
};


/*******************************************************************************************************************************
9.2.5: Multicast GEM interworking termination point

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_mc_gem_interwork_tp_op[]={
	{0, "meId",                             2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{1, "gem port network ctp conn ptr",    2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,        ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{2, "iw option",                        1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_ENUM,           ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{3, "service profile ptr",              2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,        ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{4, "not used 1",                       2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{5, "pptp counter",                     1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{6, "operational state",                1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{7, "gal profile ptr",                  2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,        ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{8, "not used 2",                       1,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT,   ATTR_FULLY_SUPPORT,&generalAttrFunc},
	{9, "ipv4 multicast addr table",        12, ATTR_ACCESS_R_W,                ATTR_FORMAT_TABLE,          ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{10,"ipv6 multicast addr table",		24, ATTR_ACCESS_R_W,				ATTR_FORMAT_TABLE,			ATTR_FULLY_SUPPORT, &generalAttrFunc},
	{255, "",                               0,  0,                              0,                          0,                      NULL}
};

omci_me_func_t omci_me_mc_gem_interwork_tp_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_mc_gem_interwork_tp_t omci_mc_gem_interwork_tp_attr_data = {0};

omci_attr_t omci_mc_gem_interwork_tp_attr ={
	(uint8_t *)&omci_mc_gem_interwork_tp_attr_data,
	sizeof(omci_mc_gem_interwork_tp_attr_data)
};

/*******************************************************************************************************************************
9.2.7: GAL Ethernet profile

********************************************************************************************************************************/

static attribute_func_t GALEthernetProfileMaxGemPayloadSizeFunc = {
	NULL,
	NULL
};

omci_attr_dscp_t omci_attr_gal_eth_prof_op[]={
	{0, "meId",                 2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "max gem payload size", 2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&GALEthernetProfileMaxGemPayloadSizeFunc},
	{255, "",                   0,  0,                              0,                          0,                      NULL}
};

omci_me_func_t omci_me_gal_eth_prof_op ={
	omci_me_general_create_op,
	omci_me_general_delete_op,
	omci_me_general_set_op,
	omci_me_general_get_op,
	NULL,
};

omci_gal_eth_prof_t omci_gal_eth_prof_attr_data = {0};

omci_attr_t omci_gal_eth_prof_attr ={
	(uint8_t *)&omci_gal_eth_prof_attr_data,
	sizeof(omci_gal_eth_prof_attr_data)
};

/*******************************************************************************************************************************
9.2.8: GAL Ethernet performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_gal_eth_pm_hist_op[]={
	{0, "meId",                     2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "interval end time",        1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "threshold data 1/2 id",    2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "discarded frames",         4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{255, "",                       0,  0,                              0,                          0,                      NULL}
};

int get_gal_eth_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(syncFlag)
    {
        /*driver do not implement, so the value is 0*/
        pm_list->pm_data.gal_eth_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.gal_eth_pm.discardFrames= 0;
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->discardFrames = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.gal_eth_pm.discardFrames);
    }
        
    return 0;
}

int omci_me_gal_eth_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_gal_eth_pm_hist_ptr gal_eth_pm_new = NULL;
    
    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    gal_eth_pm_new = (omci_gal_eth_pm_hist_ptr)me_info->attributes;
    if(gal_eth_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }
    /*driver do not implement, so the value is 0*/

	gal_eth_pm_new->intervalEndTime= pmIntervalTimes;
	gal_eth_pm_new->discardFrames = 0;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->discardFrames = 0x%x\n",__FUNCTION__,__LINE__, gal_eth_pm_new->discardFrames);
	

    return 0;
}


int omci_me_gal_eth_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ GAL_ETH_PM_HISTORY_DATA_TCA_NUM = 1};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[GAL_ETH_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[GAL_ETH_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[GAL_ETH_PM_HISTORY_DATA_TCA_NUM] = {0};
    tca_notify_info_t tca_info = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
    if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    for(i = 0; i < GAL_ETH_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_gal_eth_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_gal_eth_pm_history_get_curr_op,
};

omci_gal_eth_pm_hist_t omci_gal_eth_pm_hist_attr_data = {0};

omci_attr_t omci_gal_eth_pm_hist_attr ={
	(uint8_t *)&omci_gal_eth_pm_hist_attr_data,
	sizeof(omci_gal_eth_pm_hist_attr_data)
};

/*******************************************************************************************************************************
9.2.9: FEC performance monitoring history data

********************************************************************************************************************************/
omci_attr_dscp_t omci_attr_fec_pm_hist_op[]={
	{0, "meId",                     2,  ATTR_ACCESS_R_SET_CREATE,       ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{1, "interval end time",        1,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{2, "threshold data 1/2 id",    2,  ATTR_ACCESS_R_W_SET_CREATE,     ATTR_FORMAT_POINTER,      ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{3, "corrected bytes",          4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{4, "corrected code words",     4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{5, "uncorrected code words",   4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{6, "total code words",         4,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{7, "fec seconds",              2,  ATTR_ACCESS_R,                  ATTR_FORMAT_UNSIGNED_INT, ATTR_FULLY_SUPPORT,	&generalAttrFunc},
	{255, "",                       0,  0,                              0,                          0,                      NULL}
};


int get_fec_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    PHY_FECCONFIG_t phyFecCounter ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(gponmgr_lib_get_phy_fec_cnt(&phyFecCounter) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.fec_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.fec_pm.correctedBytes = phyFecCounter.fecCounter.corrBytes - pm_list->pm_prev_data.phyFecCnt.fecCounter.corrBytes;
    	pm_list->pm_data.fec_pm.correctedCodeWords = phyFecCounter.fecCounter.corrCodeWords - pm_list->pm_prev_data.phyFecCnt.fecCounter.corrCodeWords;
    	pm_list->pm_data.fec_pm.uncorrectedCodeWords= phyFecCounter.fecCounter.unCorrCodeWords - pm_list->pm_prev_data.phyFecCnt.fecCounter.unCorrCodeWords;
        pm_list->pm_data.fec_pm.totalCodeWords = phyFecCounter.fecCounter.totalRxCodeWords - pm_list->pm_prev_data.phyFecCnt.fecCounter.totalRxCodeWords;
        pm_list->pm_data.fec_pm.fecSeconds = phyFecCounter.fecCounter.fecSeconds - pm_list->pm_prev_data.phyFecCnt.fecCounter.fecSeconds;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->correctedBytes = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.fec_pm.correctedBytes);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->correctedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.fec_pm.correctedCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->uncorrectedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.fec_pm.uncorrectedCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->totalCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.fec_pm.totalCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.fec_pm.fecSeconds);
        
    }

    memcpy(&pm_list->pm_prev_data.phyFecCnt, &phyFecCounter, sizeof(PHY_FECCONFIG_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedBytes = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.phyFecCnt.fecCounter.corrBytes);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.phyFecCnt.fecCounter.corrCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->uncorrectedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.phyFecCnt.fecCounter.unCorrCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->totalCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.phyFecCnt.fecCounter.totalRxCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.phyFecCnt.fecCounter.fecSeconds);
        
    return 0;
}




int omci_me_fec_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_fec_pm_hist_ptr fec_pm_new = NULL;
    PHY_FECCONFIG_t phyFecCounter ={0};
	PHY_FECCONFIG_t phyFecPreData = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    fec_pm_new = (omci_fec_pm_hist_ptr)me_info->attributes;
    if(fec_pm_new == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(gponmgr_lib_get_phy_fec_cnt(&phyFecCounter) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

	omci_adpt_get_pm_pre_data(me_info->class_id,me_info->inst_id,&phyFecPreData,sizeof(PHY_FECCONFIG_t));


	fec_pm_new->intervalEndTime= pmIntervalTimes;
	fec_pm_new->correctedBytes = phyFecCounter.fecCounter.corrBytes - phyFecPreData.fecCounter.corrBytes;
	fec_pm_new->correctedCodeWords = phyFecCounter.fecCounter.corrCodeWords - phyFecPreData.fecCounter.corrCodeWords;
	fec_pm_new->uncorrectedCodeWords= phyFecCounter.fecCounter.unCorrCodeWords - phyFecPreData.fecCounter.unCorrCodeWords;
    fec_pm_new->totalCodeWords = phyFecCounter.fecCounter.totalRxCodeWords - phyFecPreData.fecCounter.totalRxCodeWords;
    fec_pm_new->fecSeconds = phyFecCounter.fecCounter.fecSeconds - phyFecPreData.fecCounter.fecSeconds;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedBytes = 0x%x\n",__FUNCTION__,__LINE__, fec_pm_new->correctedBytes);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, fec_pm_new->correctedCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->uncorrectedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, fec_pm_new->uncorrectedCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->totalCodeWords = 0x%x\n",__FUNCTION__,__LINE__, fec_pm_new->totalCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,fec_pm_new->fecSeconds);

    return 0;
}

int omci_me_fec_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ FEC_PM_HISTORY_DATA_TCA_NUM = 4};
    omci_threshold_data_1_ptr threshold_data1 = NULL;
    int i = 0;
    uint32_t currentData[FEC_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[FEC_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[FEC_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 4};
    tca_notify_info_t tca_info = {0};
    PHY_FECCONFIG_t phyFecCounter ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data1 =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data1 == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(gponmgr_lib_get_phy_fec_cnt(&phyFecCounter) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0]= phyFecCounter.fecCounter.corrBytes - pm_list->pm_prev_data.phyFecCnt.fecCounter.corrBytes;
	currentData[1] = phyFecCounter.fecCounter.corrCodeWords - pm_list->pm_prev_data.phyFecCnt.fecCounter.corrCodeWords;
	currentData[2]= phyFecCounter.fecCounter.unCorrCodeWords - pm_list->pm_prev_data.phyFecCnt.fecCounter.unCorrCodeWords;
    currentData[3] = phyFecCounter.fecCounter.fecSeconds - pm_list->pm_prev_data.phyFecCnt.fecCounter.fecSeconds;
    

    for(i = 0; i < FEC_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data1->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}
omci_me_func_t omci_me_fec_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_fec_pm_history_get_curr_op,
};

omci_fec_pm_hist_t omci_fec_pm_hist_attr_data = {0};

omci_attr_t omci_fec_pm_hist_attr ={
	(uint8_t *)&omci_fec_pm_hist_attr_data,
	sizeof(omci_fec_pm_hist_attr_data)
};


/*******************************************************************************************************************************
9.2.22: Enhanced FEC performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_enhanced_fec_pm_hist_op[]={
{0, "meId",					        2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{1, "interval end time",			1,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{2, "threshold data 64 bit id",		2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{3, "corrected bytes",			    8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{4, "corrected code words",		    8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{5, "uncorrected code words",	    8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{6, "total code words",			    8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,  &generalAttrFunc},
{7, "fec seconds",				    2,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,	&generalAttrFunc},
{255, "",                           0,  0,                              0,                          0,                      NULL}
};


int get_enhanced_fec_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    PHY_FECCONFIG_t enhancedFecCnt ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(gponmgr_lib_get_phy_fec_cnt(&enhancedFecCnt) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.enhanced_fec_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.enhanced_fec_pm.correctedBytes = enhancedFecCnt.fecCounter.corrBytes - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrBytes;
    	pm_list->pm_data.enhanced_fec_pm.correctedCodeWords = enhancedFecCnt.fecCounter.corrCodeWords - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrCodeWords;
    	pm_list->pm_data.enhanced_fec_pm.uncorrectedCodeWords= enhancedFecCnt.fecCounter.unCorrCodeWords - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.unCorrCodeWords;
        pm_list->pm_data.enhanced_fec_pm.totalCodeWords = enhancedFecCnt.fecCounter.totalRxCodeWords - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.totalRxCodeWords;
        pm_list->pm_data.enhanced_fec_pm.fecSeconds = enhancedFecCnt.fecCounter.fecSeconds - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.fecSeconds;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->correctedBytes = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_fec_pm.correctedBytes);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->correctedCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_fec_pm.correctedCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->uncorrectedCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_fec_pm.uncorrectedCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->totalCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_fec_pm.totalCodeWords);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.enhanced_fec_pm.fecSeconds);
        
    }

    memcpy(&pm_list->pm_prev_data.enhancedFecCnt, &enhancedFecCnt, sizeof(PHY_FECCONFIG_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedBytes = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrBytes);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->uncorrectedCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedFecCnt.fecCounter.unCorrCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->totalCodeWords = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedFecCnt.fecCounter.totalRxCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.enhancedFecCnt.fecCounter.fecSeconds);
        
    return 0;
}




int omci_me_enhanced_fec_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_enhanced_fec_pm_hist_ptr enhanced_fec_pm = NULL;
    PHY_FECCONFIG_t phyFecCounter ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    enhanced_fec_pm = (omci_enhanced_fec_pm_hist_ptr)me_info->attributes;
    if(enhanced_fec_pm == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(gponmgr_lib_get_phy_fec_cnt(&phyFecCounter) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

	enhanced_fec_pm->intervalEndTime= pmIntervalTimes;
	enhanced_fec_pm->correctedBytes = phyFecCounter.fecCounter.corrBytes;
	enhanced_fec_pm->correctedCodeWords = phyFecCounter.fecCounter.corrCodeWords;
	enhanced_fec_pm->uncorrectedCodeWords= phyFecCounter.fecCounter.unCorrCodeWords;
    enhanced_fec_pm->totalCodeWords = phyFecCounter.fecCounter.totalRxCodeWords;
    enhanced_fec_pm->fecSeconds = phyFecCounter.fecCounter.fecSeconds;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedBytes = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_fec_pm->correctedBytes);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->correctedCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_fec_pm->correctedCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->uncorrectedCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_fec_pm->uncorrectedCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->totalCodeWords = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_fec_pm->totalCodeWords);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fecSeconds = 0x%x\n",__FUNCTION__,__LINE__,enhanced_fec_pm->fecSeconds);

    return 0;
}

int omci_me_enhanced_fec_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ ENHANCED_FEC_PM_HISTORY_DATA_TCA_NUM = 4};
    omci_threshold_data_64bit_ptr threshold_data = NULL;
    int i = 0;
    uint64_t currentData[ENHANCED_FEC_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[ENHANCED_FEC_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[ENHANCED_FEC_PM_HISTORY_DATA_TCA_NUM] = {0, 1, 2, 4};
    tca_notify_info_t tca_info = {0};
    PHY_FECCONFIG_t phyFecCounter ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA_64_BIT){
        return 0;
    }

	threshold_data =  (omci_threshold_data_64bit_ptr)threshold_info.attributes;
	if(threshold_data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(gponmgr_lib_get_phy_fec_cnt(&phyFecCounter) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  gponmgr_lib_get_phy_fec_cnt fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0]= phyFecCounter.fecCounter.corrBytes - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrBytes;
	currentData[1] = phyFecCounter.fecCounter.corrCodeWords - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.corrCodeWords;
	currentData[2]= phyFecCounter.fecCounter.unCorrCodeWords - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.unCorrCodeWords;
    currentData[3] = phyFecCounter.fecCounter.fecSeconds - pm_list->pm_prev_data.enhancedFecCnt.fecCounter.fecSeconds;
    

    for(i = 0; i < ENHANCED_FEC_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_enhanced_fec_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_enhanced_fec_pm_history_get_curr_op,
};

omci_enhanced_fec_pm_hist_t omci_enhanced_fec_pm_hist_attr_data = {0};

omci_attr_t omci_enhanced_fec_pm_hist_attr ={
	(uint8_t *)&omci_enhanced_fec_pm_hist_attr_data,
	sizeof(omci_enhanced_fec_pm_hist_attr_data)
};


/*******************************************************************************************************************************
9.2.15: XG-PON TC performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_xgon_tc_pm_hist_op[]={
{0, "meId",					             2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{1, "interval end time",			     1,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{2, "threshold data 1/2 id",		     2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{3, "PSBd HEC Err Count",			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{4, "XGTC HEC Err Count",		         4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{5, "Unknown Prof Count",                4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{6, "Transmit XGEM Frames",	             4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{7, "Fragment XGEM Frames",			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{8, "XGEM HEC Lost Word Count",			 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{9, "XGEM Key Errors", 		             4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{10, "XGEM HEC Err Count", 			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{11, "Transmit Byte Noidle XGEM Frames", 8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{12, "Receive Byte Noidle XGEM Frames",  8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{13, "LODS Event Count", 			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{14, "LODS Event Restore Count", 		 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{15, "ONU Reactiv LODS Events", 		 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{255, "",                                0, 0,                              0,                          0,                      NULL}

};

int get_tc_data(EnhancedTCPMcounters_t *data)
{
#if 1 //implement in 10g module
	GPON_10G_TC_COUNTER_T xgponTCCounter = {0};

	if(data == NULL)
		return -1;

	omcidbgPrintf(OMCI_DEBUG_LEVEL_TRACE, "[%s][%d]  call xgponmgr_lib_get_TC_counter \n",__FUNCTION__,__LINE__);

	memset(data, 0, sizeof(EnhancedTCPMcounters_t)) ;
	if(0 != xgponmgr_lib_get_TC_counter(&xgponTCCounter)) {
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  xgponmgr_lib_get_TC_counter fail \n",__FUNCTION__,__LINE__);
		return -1;
	}

	data->PSBdHECErrCount = xgponTCCounter.PSBdHECErrCount;
	data->XGTCHECErrCount= xgponTCCounter.XGTCHECErrCount;
	data->UnknownProfCount = xgponTCCounter.UnknownProfCount;
	data->TransmitXGEMFrames= xgponTCCounter.TransmitXGEMFrames;
	data->FragmentXGEMFrames = xgponTCCounter.FragmentXGEMFrames;
	data->XGEMHECLostWordCount= xgponTCCounter.XGEMHECLostWordCount;
	data->XGEMKeyErrors = xgponTCCounter.XGEMKeyErrors;
	data->XGEMHECErrCount= xgponTCCounter.XGEMHECErrCount;
	data->TransmitByteNoidleXGEMFrames = xgponTCCounter.TransmitByteNoidleXGEMFrames;
	data->ReceiveByteNoidleXGEMFrames= xgponTCCounter.ReceiveByteNoidleXGEMFrames;
	data->LODSEventCount = xgponTCCounter.LODSEventCount;
	data->LODSEventRestoreCount= xgponTCCounter.LODSEventRestoreCount;
	data->ONUReactivLODSEvents= xgponTCCounter.ONUReactivLODSEvents;
#endif
	return 0;
}

int get_xgpon_tc_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    EnhancedTCPMcounters_t tcData ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.xgpon_tc_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.xgpon_tc_pm.PSBdHECErrCnt = tcData.PSBdHECErrCount - pm_list->pm_prev_data.xgponTc.PSBdHECErrCount;
    	pm_list->pm_data.xgpon_tc_pm.XGTCHECErrCnt = tcData.XGTCHECErrCount - pm_list->pm_prev_data.xgponTc.XGTCHECErrCount;
    	pm_list->pm_data.xgpon_tc_pm.unkonowPrfCnt = tcData.UnknownProfCount - pm_list->pm_prev_data.xgponTc.UnknownProfCount;
    	pm_list->pm_data.xgpon_tc_pm.transXGENFrame = (uint32_t)(tcData.TransmitXGEMFrames - pm_list->pm_prev_data.xgponTc.TransmitXGEMFrames);
    	pm_list->pm_data.xgpon_tc_pm.fragmentXGEMFrame = (uint32_t)(tcData.FragmentXGEMFrames - pm_list->pm_prev_data.xgponTc.FragmentXGEMFrames);
    	pm_list->pm_data.xgpon_tc_pm.XGEMHECLostWordCnt = (uint32_t)(tcData.XGEMHECLostWordCount - pm_list->pm_prev_data.xgponTc.XGEMHECLostWordCount);
    	pm_list->pm_data.xgpon_tc_pm.XGEMKeyErr = (uint32_t)(tcData.XGEMKeyErrors - pm_list->pm_prev_data.xgponTc.XGEMKeyErrors);
    	pm_list->pm_data.xgpon_tc_pm.XGEMHECErrCnt = (uint32_t)(tcData.XGEMHECErrCount - pm_list->pm_prev_data.xgponTc.XGEMHECErrCount);
    	pm_list->pm_data.xgpon_tc_pm.transByteNonIdleXGEMFrame = tcData.TransmitByteNoidleXGEMFrames - pm_list->pm_prev_data.xgponTc.TransmitByteNoidleXGEMFrames;
    	pm_list->pm_data.xgpon_tc_pm.rcvByteNonIdleXGEMFrame = tcData.ReceiveByteNoidleXGEMFrames - pm_list->pm_prev_data.xgponTc.ReceiveByteNoidleXGEMFrames;
    	pm_list->pm_data.xgpon_tc_pm.LODSEventCnt= tcData.LODSEventCount- pm_list->pm_prev_data.xgponTc.LODSEventCount;
    	pm_list->pm_data.xgpon_tc_pm.LODSEventRestoreCnt = tcData.LODSEventRestoreCount- pm_list->pm_prev_data.xgponTc.LODSEventRestoreCount;
    	pm_list->pm_data.xgpon_tc_pm.OnuReactiveByLODS = tcData.ONUReactivLODSEvents - pm_list->pm_prev_data.xgponTc.ONUReactivLODSEvents;
    	
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.PSBdHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.XGTCHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.unkonowPrfCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->transXGENFrame = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.transXGENFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->fragmentXGEMFrame = 0x%x\n",__FUNCTION__,__LINE__,pm_list->pm_data.xgpon_tc_pm.fragmentXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMHECLostWordCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.XGEMHECLostWordCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMKeyErr = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.XGEMKeyErr);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.XGEMHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.transByteNonIdleXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_data.xgpon_tc_pm.rcvByteNonIdleXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.LODSEventCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.LODSEventRestoreCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_tc_pm.OnuReactiveByLODS);

        
    }

    memcpy(&pm_list->pm_prev_data.xgponTc, &tcData, sizeof(EnhancedTCPMcounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.PSBdHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.XGTCHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.UnknownProfCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transXGENFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.TransmitXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fragmentXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.xgponTc.FragmentXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECLostWordCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.XGEMHECLostWordCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMKeyErr = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.XGEMKeyErrors);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECErrCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.XGEMHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.TransmitByteNoidleXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.xgponTc.ReceiveByteNoidleXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.LODSEventCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.LODSEventRestoreCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponTc.ONUReactivLODSEvents);
        
    return 0;
}

int omci_me_xgpon_tc_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_xgon_tc_pm_hist_ptr xgpon_tc_pm = NULL;
    EnhancedTCPMcounters_t tcData ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    xgpon_tc_pm = (omci_xgon_tc_pm_hist_ptr)me_info->attributes;
    if(xgpon_tc_pm == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

	
    xgpon_tc_pm->intervalEndTime= pmIntervalTimes;
    xgpon_tc_pm->PSBdHECErrCnt = tcData.PSBdHECErrCount;
    xgpon_tc_pm->XGTCHECErrCnt = tcData.XGTCHECErrCount;
    xgpon_tc_pm->unkonowPrfCnt = tcData.UnknownProfCount;
    xgpon_tc_pm->transXGENFrame = (uint32_t)(tcData.TransmitXGEMFrames);
    xgpon_tc_pm->fragmentXGEMFrame = (uint32_t)(tcData.FragmentXGEMFrames);
    xgpon_tc_pm->XGEMHECLostWordCnt = (uint32_t)(tcData.XGEMHECLostWordCount);
    xgpon_tc_pm->XGEMKeyErr = (uint32_t)(tcData.XGEMKeyErrors);
    xgpon_tc_pm->XGEMHECErrCnt = (uint32_t)(tcData.XGEMHECErrCount);
    xgpon_tc_pm->transByteNonIdleXGEMFrame = tcData.TransmitByteNoidleXGEMFrames;
    xgpon_tc_pm->rcvByteNonIdleXGEMFrame = tcData.ReceiveByteNoidleXGEMFrames;
    xgpon_tc_pm->LODSEventCnt= tcData.LODSEventCount;
    xgpon_tc_pm->LODSEventRestoreCnt = tcData.LODSEventRestoreCount;
    xgpon_tc_pm->OnuReactiveByLODS = tcData.ONUReactivLODSEvents;
    
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->PSBdHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->XGTCHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->unkonowPrfCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transXGENFrame = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->transXGENFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fragmentXGEMFrame = 0x%x\n",__FUNCTION__,__LINE__,xgpon_tc_pm->fragmentXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECLostWordCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->XGEMHECLostWordCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMKeyErr = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->XGEMKeyErr);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->XGEMHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, xgpon_tc_pm->transByteNonIdleXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,xgpon_tc_pm->rcvByteNonIdleXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->LODSEventCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->LODSEventRestoreCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, xgpon_tc_pm->OnuReactiveByLODS);
	

    return 0;
}

int omci_me_xgpon_tc_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ XGPON_TC_PM_HISTORY_DATA_TCA_NUM = 6};
    omci_threshold_data_1_ptr threshold_data = NULL;
    int i = 0;
    uint32_t currentData[XGPON_TC_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[XGPON_TC_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[XGPON_TC_PM_HISTORY_DATA_TCA_NUM] = {1, 2, 3, 4, 5, 6};
    tca_notify_info_t tca_info = {0};
    EnhancedTCPMcounters_t tcData ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0] = tcData.PSBdHECErrCount - pm_list->pm_prev_data.xgponTc.PSBdHECErrCount;
	currentData[1] = tcData.XGTCHECErrCount - pm_list->pm_prev_data.xgponTc.XGTCHECErrCount;
	currentData[2] = tcData.UnknownProfCount - pm_list->pm_prev_data.xgponTc.UnknownProfCount;
    currentData[3] = (uint32_t)(tcData.XGEMHECLostWordCount - pm_list->pm_prev_data.xgponTc.XGEMHECLostWordCount);
    currentData[4] = (uint32_t)(tcData.XGEMKeyErrors - pm_list->pm_prev_data.xgponTc.XGEMKeyErrors);
    currentData[5] = (uint32_t)(tcData.XGEMHECErrCount - pm_list->pm_prev_data.xgponTc.XGEMHECErrCount);
    

    for(i = 0; i < XGPON_TC_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_xgon_tc_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_xgpon_tc_pm_history_get_curr_op,
};

omci_xgon_tc_pm_hist_t omci_xgon_tc_pm_hist_attr_data = {0};

omci_attr_t omci_xgon_tc_pm_hist_attr ={
	(uint8_t *)&omci_xgon_tc_pm_hist_attr_data,
	sizeof(omci_xgon_tc_pm_hist_attr_data)
};

/*******************************************************************************************************************************
9.2.16: XG-PON downstream management performance monitoring history data(Class ID 345)   2017 G988

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_xgon_ds_mgnt_pm_hist_op[]={
{0, "meId",				2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{1, "interval end time",		1,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{2, "threshold data 1/2 id",		2,	ATTR_ACCESS_R_W_SET_CREATE,	        ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{3, "PLOAM MIC Err Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{4, "DS PLOAM Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{5, "Profile Msg Rx",			4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{6, "Ranging Time Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{7, "Deactivate ONU ID Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{8, "Disable SN Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{9, "Request Rgistration Msg Rx",	4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{10, "Assign Alloc ID Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{11, "Key Control Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{12, "Sleep Allow Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{13, "Base OMCI Msg Rx Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{14, "Extended OMCI Msg Rx Count",	4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{15, "Assign ONU ID Msg Rx",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{16, "OMCI Mic Err Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{255, "",				0,	0,					0,                              0,                      NULL}

};

int get_ds_mgnt_data(GPON_10G_DS_MGNT_COUNTER_T *data)
{
	if(data == NULL)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  parameter is NULL fail\n",__FUNCTION__,__LINE__);
		return -1;
	}

	memset(data, 0, sizeof(GPON_10G_DS_MGNT_COUNTER_T)) ;
	if(0 != xgponmgr_lib_get_ds_mgnt_counter(data)) {
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  xgponmgr_lib_get_ds_mgnt_counter fail \n",__FUNCTION__,__LINE__);
		return -1;
	}
	data->BaseOmciMsgRx = OmciPktRxCnt.BaseOmciMsgRx;
	data->ExtOmciMsgRx = OmciPktRxCnt.ExtOmciMsgRx;
	return 0;
}

int get_xgpon_ds_mgnt_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    GPON_10G_DS_MGNT_COUNTER_T DsMgntData = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(get_ds_mgnt_data(&DsMgntData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_ds_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.xgpon_ds_mgnt_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.PloamMicErrCnt = DsMgntData.PloamMicErrCnt - pm_list->pm_prev_data.xgponDsMgnt.PloamMicErrCnt;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.DsPloamMsgCnt = DsMgntData.DsPloamMsgCnt - pm_list->pm_prev_data.xgponDsMgnt.DsPloamMsgCnt;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.ProfileMsgRx = DsMgntData.ProfileMsgRx - pm_list->pm_prev_data.xgponDsMgnt.ProfileMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.RangeTimeMsgRx = DsMgntData.RangeTimeMsgRx - pm_list->pm_prev_data.xgponDsMgnt.RangeTimeMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.DeactOnuIdMsgRx = DsMgntData.DeactOnuIdMsgRx - pm_list->pm_prev_data.xgponDsMgnt.PloamMicErrCnt;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.DisableSnMsgRx = DsMgntData.DisableSnMsgRx - pm_list->pm_prev_data.xgponDsMgnt.DisableSnMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.ReqRegMsgRx = DsMgntData.ReqRegMsgRx - pm_list->pm_prev_data.xgponDsMgnt.ReqRegMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.AssignAllocIdMsgRx = DsMgntData.AssignAllocIdMsgRx - pm_list->pm_prev_data.xgponDsMgnt.AssignAllocIdMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.KeyCtrlMsgRx = DsMgntData.KeyCtrlMsgRx - pm_list->pm_prev_data.xgponDsMgnt.KeyCtrlMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.SleepAllowMsgRx = DsMgntData.SleepAllowMsgRx - pm_list->pm_prev_data.xgponDsMgnt.SleepAllowMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.BaseOmciMsgRx = DsMgntData.BaseOmciMsgRx - pm_list->pm_prev_data.xgponDsMgnt.BaseOmciMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.ExtOmciMsgRx = DsMgntData.ExtOmciMsgRx - pm_list->pm_prev_data.xgponDsMgnt.ExtOmciMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.AssignOnuIdMsgRx = DsMgntData.AssignOnuIdMsgRx - pm_list->pm_prev_data.xgponDsMgnt.AssignOnuIdMsgRx;
    	pm_list->pm_data.xgpon_ds_mgnt_pm.OmciMicErrCnt = DsMgntData.OmciMicErrCnt - pm_list->pm_prev_data.xgponDsMgnt.OmciMicErrCnt;
		
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->PloamMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.PloamMicErrCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->DsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.DsPloamMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->ProfileMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.ProfileMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->RangeTimeMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.RangeTimeMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->DeactOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.DeactOnuIdMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->DisableSnMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.DisableSnMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->ReqRegMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.ReqRegMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->AssignAllocIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.AssignAllocIdMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->KeyCtrlMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.KeyCtrlMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->SleepAllowMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.SleepAllowMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->BaseOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.BaseOmciMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->ExtOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.ExtOmciMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->AssignOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.AssignOnuIdMsgRx);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->OmciMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_ds_mgnt_pm.OmciMicErrCnt);
        
    }

    memcpy(&pm_list->pm_prev_data.xgponDsMgnt, &DsMgntData, sizeof(GPON_10G_DS_MGNT_COUNTER_T));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PloamMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.PloamMicErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.DsPloamMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ProfileMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.ProfileMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->RangeTimeMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.RangeTimeMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DeactOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.DeactOnuIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DisableSnMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.DisableSnMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ReqRegMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.ReqRegMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AssignAllocIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.AssignAllocIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->KeyCtrlMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.KeyCtrlMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SleepAllowMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.SleepAllowMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->BaseOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.BaseOmciMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ExtOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.ExtOmciMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AssignOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.AssignOnuIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OmciMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponDsMgnt.OmciMicErrCnt);
        
    return 0;
}

int omci_me_xgpon_ds_mgnt_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_xgon_ds_mgnt_pm_hist_ptr xgpon_ds_mgnt_pm = NULL;
    GPON_10G_DS_MGNT_COUNTER_T DsMgntData = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    xgpon_ds_mgnt_pm = (omci_xgon_ds_mgnt_pm_hist_ptr)me_info->attributes;
    if(xgpon_ds_mgnt_pm == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_ds_mgnt_data(&DsMgntData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_ds_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	
    xgpon_ds_mgnt_pm->intervalEndTime= pmIntervalTimes;
    xgpon_ds_mgnt_pm->PloamMicErrCnt = DsMgntData.PloamMicErrCnt;
    xgpon_ds_mgnt_pm->DsPloamMsgCnt = DsMgntData.DsPloamMsgCnt;
    xgpon_ds_mgnt_pm->ProfileMsgRx = DsMgntData.ProfileMsgRx;
    xgpon_ds_mgnt_pm->RangeTimeMsgRx = DsMgntData.RangeTimeMsgRx;
    xgpon_ds_mgnt_pm->DeactOnuIdMsgRx = DsMgntData.DeactOnuIdMsgRx;
    xgpon_ds_mgnt_pm->DisableSnMsgRx = DsMgntData.DisableSnMsgRx;
    xgpon_ds_mgnt_pm->ReqRegMsgRx = DsMgntData.ReqRegMsgRx;
    xgpon_ds_mgnt_pm->AssignAllocIdMsgRx = DsMgntData.AssignAllocIdMsgRx;
    xgpon_ds_mgnt_pm->KeyCtrlMsgRx = DsMgntData.KeyCtrlMsgRx;
    xgpon_ds_mgnt_pm->SleepAllowMsgRx = DsMgntData.SleepAllowMsgRx;
    xgpon_ds_mgnt_pm->BaseOmciMsgRx = DsMgntData.BaseOmciMsgRx;
    xgpon_ds_mgnt_pm->ExtOmciMsgRx = DsMgntData.ExtOmciMsgRx;
    xgpon_ds_mgnt_pm->AssignOnuIdMsgRx = DsMgntData.AssignOnuIdMsgRx;
    xgpon_ds_mgnt_pm->OmciMicErrCnt = DsMgntData.OmciMicErrCnt;
	
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PloamMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->PloamMicErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->DsPloamMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ProfileMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->ProfileMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->RangeTimeMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->RangeTimeMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DeactOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->DeactOnuIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->DisableSnMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->DisableSnMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ReqRegMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->ReqRegMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AssignAllocIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->AssignAllocIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->KeyCtrlMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->KeyCtrlMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SleepAllowMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->SleepAllowMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->BaseOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->BaseOmciMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->ExtOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->ExtOmciMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AssignOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->AssignOnuIdMsgRx);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OmciMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_ds_mgnt_pm->OmciMicErrCnt);

    return 0;
}

int omci_me_xgpon_ds_mgnt_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ XGPON_DS_MGNT_PM_HISTORY_DATA_TCA_NUM = 2};
    omci_threshold_data_1_ptr threshold_data = NULL;
    int i = 0;
    uint32_t currentData[XGPON_DS_MGNT_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[XGPON_DS_MGNT_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[XGPON_DS_MGNT_PM_HISTORY_DATA_TCA_NUM] = {1, 2};
    tca_notify_info_t tca_info = {0};
    GPON_10G_DS_MGNT_COUNTER_T DsMgntData ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1) {
        return 0;
	}

	threshold_data =  (omci_threshold_data_1_ptr)threshold_info.attributes;
	if(threshold_data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_ds_mgnt_data(&DsMgntData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_ds_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
    currentData[0] = DsMgntData.PloamMicErrCnt - pm_list->pm_prev_data.xgponDsMgnt.PloamMicErrCnt;
    currentData[1] = DsMgntData.OmciMicErrCnt - pm_list->pm_prev_data.xgponDsMgnt.OmciMicErrCnt;
    

    for(i = 0; i < XGPON_DS_MGNT_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
    }

    return 0;
    
}


omci_me_func_t omci_me_xgon_ds_mgnt_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_xgpon_ds_mgnt_pm_history_get_curr_op,
};

omci_xgon_ds_mgnt_pm_hist_t omci_xgon_ds_mgnt_pm_hist_attr_data = {0};

omci_attr_t omci_xgon_ds_mgnt_pm_hist_attr ={
	(uint8_t *)&omci_xgon_ds_mgnt_pm_hist_attr_data,
	sizeof(omci_xgon_ds_mgnt_pm_hist_attr_data)
};

/*******************************************************************************************************************************
9.2.17: XG-PON upstream management performance monitoring history data(Class ID 346)   2017 G988

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_xgon_us_mgnt_pm_hist_op[]={
{0, "meId",				2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{1, "interval end time",		1,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{2, "threshold data 1/2 id",		2,	ATTR_ACCESS_R_W_SET_CREATE,		ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{3, "US PLOAM Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{4, "SN ONU Msg Count",			4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{5, "Registration Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{6, "Key Report Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{7, "Acknowledge Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{8, "Sleep Request Msg Count",		4,	ATTR_ACCESS_R,				ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{255, "",				0,	0,					0,                              0,                      NULL}

};

int get_us_mgnt_data(GPON_10G_US_MGNT_COUNTER_T *data)
{
	if(data == NULL)
	{
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  parameter is NULL fail\n",__FUNCTION__,__LINE__);
		return -1;
	}

	memset(data, 0, sizeof(GPON_10G_US_MGNT_COUNTER_T)) ;
	if(0 != xgponmgr_lib_get_us_mgnt_counter(data)) {
		omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  xgponmgr_lib_get_us_mgnt_counter fail \n",__FUNCTION__,__LINE__);
		return -1;
	}
	return 0;
}

int get_xgpon_us_mgnt_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    GPON_10G_US_MGNT_COUNTER_T UsMgntData = {0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(get_us_mgnt_data(&UsMgntData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_us_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.xgpon_us_mgnt_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.xgpon_us_mgnt_pm.UsPloamMsgCnt = UsMgntData.UsPloamMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.UsPloamMsgCnt;
    	pm_list->pm_data.xgpon_us_mgnt_pm.SnOnuMsgCnt = UsMgntData.SnOnuMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.SnOnuMsgCnt;
    	pm_list->pm_data.xgpon_us_mgnt_pm.RegMsgCnt = UsMgntData.RegMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.RegMsgCnt;
    	pm_list->pm_data.xgpon_us_mgnt_pm.KeyRptMsgCnt = UsMgntData.KeyRptMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.KeyRptMsgCnt;
    	pm_list->pm_data.xgpon_us_mgnt_pm.AckMsgCnt = UsMgntData.AckMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.AckMsgCnt;
    	pm_list->pm_data.xgpon_us_mgnt_pm.SleepReqMsgCnt = UsMgntData.SleepReqMsgCnt - pm_list->pm_prev_data.xgponUsMgnt.SleepReqMsgCnt;

        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->UsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.UsPloamMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->SnOnuMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.SnOnuMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->RegMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.RegMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->KeyRptMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.KeyRptMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->AckMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.AckMsgCnt);
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->SleepReqMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.xgpon_us_mgnt_pm.SleepReqMsgCnt);
    }

    memcpy(&pm_list->pm_prev_data.xgponDsMgnt, &UsMgntData, sizeof(GPON_10G_US_MGNT_COUNTER_T));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->UsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.UsPloamMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SnOnuMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.SnOnuMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->RegMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.RegMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->KeyRptMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.KeyRptMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AckMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.AckMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SleepReqMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.xgponUsMgnt.SleepReqMsgCnt);
       
    return 0;
}

int omci_me_xgpon_us_mgnt_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_xgon_us_mgnt_pm_hist_ptr xgpon_us_mgnt_pm = NULL;
    GPON_10G_US_MGNT_COUNTER_T UsMgntData = {0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    xgpon_us_mgnt_pm = (omci_xgon_us_mgnt_pm_hist_ptr)me_info->attributes;
    if(xgpon_us_mgnt_pm == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_us_mgnt_data(&UsMgntData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_ds_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
	
    xgpon_us_mgnt_pm->intervalEndTime= pmIntervalTimes;
    xgpon_us_mgnt_pm->UsPloamMsgCnt = UsMgntData.UsPloamMsgCnt;
    xgpon_us_mgnt_pm->SnOnuMsgCnt = UsMgntData.SnOnuMsgCnt;
    xgpon_us_mgnt_pm->RegMsgCnt = UsMgntData.RegMsgCnt;
    xgpon_us_mgnt_pm->KeyRptMsgCnt = UsMgntData.KeyRptMsgCnt;
    xgpon_us_mgnt_pm->AckMsgCnt = UsMgntData.AckMsgCnt;
    xgpon_us_mgnt_pm->SleepReqMsgCnt = UsMgntData.SleepReqMsgCnt;
	
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->UsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->UsPloamMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SnOnuMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->SnOnuMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->RegMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->RegMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->KeyRptMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->KeyRptMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->AckMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->AckMsgCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->SleepReqMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, xgpon_us_mgnt_pm->SleepReqMsgCnt);

    return 0;
}


omci_me_func_t omci_me_xgon_us_mgnt_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_xgpon_us_mgnt_pm_history_get_curr_op,
};

omci_xgon_us_mgnt_pm_hist_t omci_xgon_us_mgnt_pm_hist_attr_data = {0};

omci_attr_t omci_xgon_us_mgnt_pm_hist_attr ={
	(uint8_t *)&omci_xgon_us_mgnt_pm_hist_attr_data,
	sizeof(omci_xgon_us_mgnt_pm_hist_attr_data)
};

/*******************************************************************************************************************************
9.2.23: Enhanced TC performance monitoring history data

********************************************************************************************************************************/

omci_attr_dscp_t omci_attr_enhanced_tc_pm_hist_op[]={
{0, "meId",					             2,	ATTR_ACCESS_R_SET_CREATE,		ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{1, "interval end time",			     1,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{2, "threshold data 64 bit id",		     2,	ATTR_ACCESS_R_W_SET_CREATE,	    ATTR_FORMAT_POINTER,		ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{3, "PSBd HEC Err Count",			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{4, "XGTC HEC Err Count",		         4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{5, "Unknown Prof Count",                4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{6, "Transmit XGEM Frames",	             4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{7, "Fragment XGEM Frames",			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{8, "XGEM HEC Lost Word Count",			 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{9, "XGEM Key Errors", 		             4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{10, "XGEM HEC Err Count", 			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{11, "Transmit Byte Noidle XGEM Frames", 8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{12, "Receive Byte Noidle XGEM Frames",  8,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{13, "LODS Event Count", 			     4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{14, "LODS Event Restore Count", 		 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{15, "ONU Reactiv LODS Events", 		 4,	ATTR_ACCESS_R,					ATTR_FORMAT_UNSIGNED_INT,	ATTR_FULLY_SUPPORT,    &generalAttrFunc},
{255, "",                                0, 0,                              0,                          0,                      NULL}
};

int get_enhanced_tc_pm_history_data(pm_history_data_list_ptr pm_list, uint8_t syncFlag)
{
    EnhancedTCPMcounters_t tcData ={0};

    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    
    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(syncFlag)
    {
        pm_list->pm_data.enhanced_tc_pm.intervalEndTime= pmIntervalTimes;
    	pm_list->pm_data.enhanced_tc_pm.PSBdHECErrCnt = tcData.PSBdHECErrCount - pm_list->pm_prev_data.enhancedTc.PSBdHECErrCount;
    	pm_list->pm_data.enhanced_tc_pm.XGTCHECErrCnt = tcData.XGTCHECErrCount - pm_list->pm_prev_data.enhancedTc.XGTCHECErrCount;
    	pm_list->pm_data.enhanced_tc_pm.unkonowPrfCnt = tcData.UnknownProfCount - pm_list->pm_prev_data.enhancedTc.UnknownProfCount;
    	pm_list->pm_data.enhanced_tc_pm.transXGENFrame = tcData.TransmitXGEMFrames - pm_list->pm_prev_data.enhancedTc.TransmitXGEMFrames;
    	pm_list->pm_data.enhanced_tc_pm.fragmentXGEMFrame = tcData.FragmentXGEMFrames - pm_list->pm_prev_data.enhancedTc.FragmentXGEMFrames;
    	pm_list->pm_data.enhanced_tc_pm.XGEMHECLostWordCnt = tcData.XGEMHECLostWordCount - pm_list->pm_prev_data.enhancedTc.XGEMHECLostWordCount;
    	pm_list->pm_data.enhanced_tc_pm.XGEMKeyErr = tcData.XGEMKeyErrors - pm_list->pm_prev_data.enhancedTc.XGEMKeyErrors;
    	pm_list->pm_data.enhanced_tc_pm.XGEMHECErrCnt = tcData.XGEMHECErrCount - pm_list->pm_prev_data.enhancedTc.XGEMHECErrCount;
    	pm_list->pm_data.enhanced_tc_pm.transByteNonIdleXGEMFrame = tcData.TransmitByteNoidleXGEMFrames - pm_list->pm_prev_data.enhancedTc.TransmitByteNoidleXGEMFrames;
    	pm_list->pm_data.enhanced_tc_pm.rcvByteNonIdleXGEMFrame = tcData.ReceiveByteNoidleXGEMFrames - pm_list->pm_prev_data.enhancedTc.ReceiveByteNoidleXGEMFrames;
    	pm_list->pm_data.enhanced_tc_pm.LODSEventCnt= tcData.LODSEventCount- pm_list->pm_prev_data.enhancedTc.LODSEventCount;
    	pm_list->pm_data.enhanced_tc_pm.LODSEventRestoreCnt= tcData.LODSEventRestoreCount - pm_list->pm_prev_data.enhancedTc.LODSEventRestoreCount;
    	pm_list->pm_data.enhanced_tc_pm.OnuReactiveByLODS = tcData.ONUReactivLODSEvents - pm_list->pm_prev_data.enhancedTc.ONUReactivLODSEvents;
    	
        omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.PSBdHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.XGTCHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.unkonowPrfCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->transXGENFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.transXGENFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->fragmentXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_data.enhanced_tc_pm.fragmentXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMHECLostWordCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.XGEMHECLostWordCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMKeyErr = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.XGEMKeyErr);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->XGEMHECErrCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.XGEMHECErrCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.transByteNonIdleXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_data.enhanced_tc_pm.rcvByteNonIdleXGEMFrame);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.LODSEventCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.LODSEventRestoreCnt);
    	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]15min->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_data.enhanced_tc_pm.OnuReactiveByLODS);

        
    }

    memcpy(&pm_list->pm_prev_data.enhancedTc, &tcData, sizeof(EnhancedTCPMcounters_t));

    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.PSBdHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.XGTCHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.UnknownProfCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transXGENFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.TransmitXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fragmentXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.enhancedTc.FragmentXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECLostWordCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.XGEMHECLostWordCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMKeyErr = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.XGEMKeyErrors);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECErrCnt = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.XGEMHECErrCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.TransmitByteNoidleXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,pm_list->pm_prev_data.enhancedTc.ReceiveByteNoidleXGEMFrames);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.LODSEventCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.LODSEventRestoreCount);
	omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, pm_list->pm_prev_data.enhancedTc.ONUReactivLODSEvents);
        
    return 0;
}

int omci_me_enhanced_tc_pm_history_get_curr_op(management_entry_ptr me_entry, omci_me_info_ptr me_info)
{
    omci_enhanced_tc_pm_hist_ptr enhanced_tc_pm = NULL;
    EnhancedTCPMcounters_t tcData ={0};

    if(me_entry == NULL || me_info == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]pointer is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    enhanced_tc_pm = (omci_enhanced_tc_pm_hist_ptr)me_info->attributes;
    if(enhanced_tc_pm == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]me info attribute is NULL.\n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

	
    enhanced_tc_pm->intervalEndTime= pmIntervalTimes;
    enhanced_tc_pm->PSBdHECErrCnt = tcData.PSBdHECErrCount;
    enhanced_tc_pm->XGTCHECErrCnt = tcData.XGTCHECErrCount;
    enhanced_tc_pm->unkonowPrfCnt = tcData.UnknownProfCount;
    enhanced_tc_pm->transXGENFrame = tcData.TransmitXGEMFrames;
    enhanced_tc_pm->fragmentXGEMFrame = tcData.FragmentXGEMFrames;
    enhanced_tc_pm->XGEMHECLostWordCnt = tcData.XGEMHECLostWordCount;
    enhanced_tc_pm->XGEMKeyErr = tcData.XGEMKeyErrors;
    enhanced_tc_pm->XGEMHECErrCnt = tcData.XGEMHECErrCount;
    enhanced_tc_pm->transByteNonIdleXGEMFrame = tcData.TransmitByteNoidleXGEMFrames;
    enhanced_tc_pm->rcvByteNonIdleXGEMFrame = tcData.ReceiveByteNoidleXGEMFrames;
    enhanced_tc_pm->LODSEventCnt= tcData.LODSEventCount;
    enhanced_tc_pm->LODSEventRestoreCnt = tcData.LODSEventRestoreCount;
    enhanced_tc_pm->OnuReactiveByLODS = tcData.ONUReactivLODSEvents;
    
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->PSBdHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->PSBdHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGTCHECErrCnt = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->XGTCHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->unkonowPrfCnt = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->unkonowPrfCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transXGENFrame = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_tc_pm->transXGENFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->fragmentXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,enhanced_tc_pm->fragmentXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECLostWordCnt = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_tc_pm->XGEMHECLostWordCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMKeyErr = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_tc_pm->XGEMKeyErr);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->XGEMHECErrCnt = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_tc_pm->XGEMHECErrCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->transByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__, enhanced_tc_pm->transByteNonIdleXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->rcvByteNonIdleXGEMFrame = 0x%llx\n",__FUNCTION__,__LINE__,enhanced_tc_pm->rcvByteNonIdleXGEMFrame);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventCnt = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->LODSEventCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->LODSEventRestoreCnt = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->LODSEventRestoreCnt);
    omcidbgPrintf(OMCI_DEBUG_LEVEL_DEBUG,"[%s][%d]->OnuReactiveByLODS = 0x%x\n",__FUNCTION__,__LINE__, enhanced_tc_pm->OnuReactiveByLODS);
	

    return 0;
}

int omci_me_enhanced_tc_pm_history_notify(pm_history_data_list_ptr pm_list, omci_me_info_t threshold_info)
{
    enum{ ENHANCED_TC_PM_HISTORY_DATA_TCA_NUM = 6};
    omci_threshold_data_64bit_ptr threshold_data = NULL;
    int i = 0;
    uint64_t currentData[ENHANCED_TC_PM_HISTORY_DATA_TCA_NUM] = {0};
    static uint8_t reportFlag[ENHANCED_TC_PM_HISTORY_DATA_TCA_NUM] = {0};
    uint8_t alarm_num[ENHANCED_TC_PM_HISTORY_DATA_TCA_NUM] = {1, 2, 3, 4, 5, 6};
    tca_notify_info_t tca_info = {0};
    EnhancedTCPMcounters_t tcData ={0};
    
    if(pm_list == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  pm_list is NULL fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    if(omci_pm_is_end_of_interval_time())
    {
        memset(reportFlag, 0, sizeof(reportFlag));
        return 0;
    }
    if(threshold_info.class_id != OMCI_CLASS_ID_THRESHOLD_DATA1){
        return 0;
    }

	threshold_data =  (omci_threshold_data_64bit_ptr)threshold_info.attributes;
	if(threshold_data == NULL)
    {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  threshold value is NULL \n",__FUNCTION__,__LINE__);
        return -1;
    }

    if(get_tc_data(&tcData) != 0) {
        omcidbgPrintf(OMCI_DEBUG_LEVEL_ERROR, "[%s][%d]  get_tc_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }

    /*monitor 15min interval tca attribute value*/
	currentData[0] = tcData.PSBdHECErrCount - pm_list->pm_prev_data.enhancedTc.PSBdHECErrCount;
	currentData[1] = tcData.XGTCHECErrCount - pm_list->pm_prev_data.enhancedTc.XGTCHECErrCount;
	currentData[2] = tcData.UnknownProfCount - pm_list->pm_prev_data.enhancedTc.UnknownProfCount;
    currentData[3] = tcData.XGEMHECLostWordCount - pm_list->pm_prev_data.enhancedTc.XGEMHECLostWordCount;
    currentData[4] = tcData.XGEMKeyErrors - pm_list->pm_prev_data.enhancedTc.XGEMKeyErrors;
    currentData[5] = tcData.XGEMHECErrCount - pm_list->pm_prev_data.enhancedTc.XGEMHECErrCount;
    

    for(i = 0; i < ENHANCED_TC_PM_HISTORY_DATA_TCA_NUM; i++)
    {
        tca_info.classId = pm_list->classId;
        tca_info.instId = pm_list->instId;
        tca_info.currentData = currentData[i];
        tca_info.threshold = threshold_data->thresholdValue[i];
        tca_info.alarm_num = alarm_num[i];
        tca_info.reportFlag = reportFlag[i];

        reportFlag[i] = omci_pm_report_alarm_by_tca_info(tca_info, 0);
	}

	return 0;
    
}


omci_me_func_t omci_me_enhanced_tc_pm_hist_op ={
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_create_del_op,
	omci_me_general_pm_history_set_op,
	omci_me_general_pm_history_get_op,
	omci_me_enhanced_tc_pm_history_get_curr_op,
};

omci_enhanced_tc_pm_hist_t omci_enhanced_tc_pm_hist_attr_data = {0};

omci_attr_t omci_enhanced_tc_pm_hist_attr ={
	(uint8_t *)&omci_enhanced_tc_pm_hist_attr_data,
	sizeof(omci_enhanced_tc_pm_hist_attr_data)
};



/*****************************************************************************************
ONLY FOR TEST CMD
*******************************************************************************************/
int omci_test_pm_info(void)
{
    GPON_10G_DS_MGNT_COUNTER_T DsMgntData = {0};
    GPON_10G_US_MGNT_COUNTER_T UsMgntData = {0};

    if(get_ds_mgnt_data(&DsMgntData) != 0) {
        omciScreenPrintf("[%s][%d]  get_ds_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    omciScreenPrintf("[%s][%d]PloamMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.PloamMicErrCnt);
    omciScreenPrintf("[%s][%d]DsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.DsPloamMsgCnt);
    omciScreenPrintf("[%s][%d]ProfileMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.ProfileMsgRx);
    omciScreenPrintf("[%s][%d]RangeTimeMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.RangeTimeMsgRx);
    omciScreenPrintf("[%s][%d]DeactOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.DeactOnuIdMsgRx);
    omciScreenPrintf("[%s][%d]DisableSnMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.DisableSnMsgRx);
    omciScreenPrintf("[%s][%d]ReqRegMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.ReqRegMsgRx);
    omciScreenPrintf("[%s][%d]AssignAllocIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.AssignAllocIdMsgRx);
    omciScreenPrintf("[%s][%d]KeyCtrlMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.KeyCtrlMsgRx);
    omciScreenPrintf("[%s][%d]SleepAllowMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.SleepAllowMsgRx);
    omciScreenPrintf("[%s][%d]BaseOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.BaseOmciMsgRx);
    omciScreenPrintf("[%s][%d]ExtOmciMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.ExtOmciMsgRx);
    omciScreenPrintf("[%s][%d]AssignOnuIdMsgRx = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.AssignOnuIdMsgRx);
    omciScreenPrintf("[%s][%d]OmciMicErrCnt = 0x%x\n",__FUNCTION__,__LINE__, DsMgntData.OmciMicErrCnt);

    if(get_us_mgnt_data(&UsMgntData) != 0) {
        omciScreenPrintf("[%s][%d]  get_us_mgnt_data fail\n",__FUNCTION__,__LINE__);
        return -1;
    }
    omciScreenPrintf("[%s][%d]UsPloamMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.UsPloamMsgCnt);
    omciScreenPrintf("[%s][%d]SnOnuMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.SnOnuMsgCnt);
    omciScreenPrintf("[%s][%d]RegMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.RegMsgCnt);
    omciScreenPrintf("[%s][%d]KeyRptMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.KeyRptMsgCnt);
    omciScreenPrintf("[%s][%d]AckMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.AckMsgCnt);
    omciScreenPrintf("[%s][%d]SleepReqMsgCnt = 0x%x\n",__FUNCTION__,__LINE__, UsMgntData.SleepReqMsgCnt);

    return 0;
}


